import requests

# 封装requests
def request(url, method="GET", headers=None, params=None, data=None, json_data=None):
    try:
        if method.upper() == "GET":
            response = requests.request(method, url, headers=headers, params=params,timeout = 7)
        elif method.upper() == "POST":
            response = requests.request(method, url, headers=headers, data=data, json=json_data,timeout = 7)
        else:
            return {"success": False, "message": "Unsupported HTTP method"}
        return response.json()

    except requests.Timeout:
        return {"success": False, "message": "Request timed out"}

    except Exception as e:
        return {"success": False, "message": f"{e}"}